home *** CD-ROM | disk | FTP | other *** search
- Path: news.InfoChan.COM!news
- From: alanj@infochan.com (Alan Johnston)
- Newsgroups: comp.lang.c++
- Subject: Re: A simple question for all the C++ gurus out there!
- Date: Tue, 13 Feb 1996 20:32:15 GMT
- Organization: InfoChannel Ltd
- Message-ID: <4fqshj$jje@daffodil.InfoChan.COM>
- References: <3120F95F.659@iglou.com>
- NNTP-Posting-Host: ntsa22.infochan.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- "Abe L. Getchell" <panther@iglou.com> wrote:
-
- >I am trying to write a public member function that will use a private
- >data member from which it inherited from the base class. This won't compile.
- >It gives me an error message like "A::a private data member not accessible in
- >class B". Why won't this work if the prvate data member being inherited from
- >the base class A be a private data member of the derived class?
-
- >Abe L. Getchell
-
- >Please respond via E-Mail if possible...
-
- Private members in base classes are not accessible in derived classes,
- unless you make the derived class a friend of the base class.
- Protected members are accessible in derived classes, which gives you
- pretty much the same result. Like this:
-
- class A {
- protected:
- int a;
- }
-
- class B : public A {
- public:
- int GetA() { return a; };
- }
-
-